package site.lanmushan.quiz.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import site.lanmushan.common.dto.Message;
import org.springframework.web.bind.annotation.*;
import site.lanmushan.common.dto.QueryInfo;
import site.lanmushan.common.query.annotations.RequestQueryInfo;
import site.lanmushan.common.query.controller.BaseController;
import site.lanmushan.quiz.api.ao.QuizTbQuestionAnswerRecordAo;
import site.lanmushan.quiz.api.ao.SubmitAnswerAo;
import site.lanmushan.quiz.api.entity.QuizTbQuestionAnswerRecord;
import site.lanmushan.quiz.api.service.IQuizTbQuestionAnswerRecordService;

import java.util.List;
import javax.validation.Valid;

import site.lanmushan.common.bizlog.annotations.BizLog;
import site.lanmushan.common.bizlog.consts.BizLogType;
import site.lanmushan.quiz.api.vo.ExamQuestionListVo;
import site.lanmushan.quiz.api.vo.QuestionAnswersVo;

/**
 * @author $author
 * 测验答题记录
 */
@RestController
@RequestMapping(name = "测验答题记录", value = "/QuizTbQuestionAnswerRecord")
@Slf4j
public class QuizTbQuestionAnswerRecordController extends BaseController {
    @Autowired
    IQuizTbQuestionAnswerRecordService quizTbQuestionAnswerRecordService;

    @BizLog(name = "测验答题记录-分页条件查询", bizType = BizLogType.SELECT)
    @GetMapping(name = "分页条件查询", value = "/selectPageList")
    public Message<List<QuizTbQuestionAnswerRecord>> selectPageList(@RequestQueryInfo QueryInfo queryInfo) {
        List<QuizTbQuestionAnswerRecord> quizTbQuestionAnswerRecordList = quizTbQuestionAnswerRecordService.selectPageList(queryInfo);
        return Message.getInstance().setData(quizTbQuestionAnswerRecordList).success("查询成功");
    }

    @BizLog(name = "提交答案", bizType = BizLogType.INSERT)
    @PostMapping(name = "提交答案", value = "/doSubmitAnswer")
    public Message<Long> doSubmitAnswer(@RequestBody @Valid SubmitAnswerAo entityAo) {
        quizTbQuestionAnswerRecordService.doSubmitAnswer(entityAo);
        return Message.getInstance().setData(entityAo).success();
    }
    @GetMapping(name = "获取问题详情以及答题情况", value = "/selectQuestionAndAnswersById")
    public Message<QuestionAnswersVo> selectQuestionAndOptionsById(@RequestParam Long id,Long examId) {
        QuestionAnswersVo resultEntity = quizTbQuestionAnswerRecordService.selectQuestionAndOptionsById(id,examId);
        return Message.getInstance().setData(resultEntity).success("查询成功");
    }
    @BizLog(name = "测验答题-获取问题列表", bizType = BizLogType.SELECT)
    @GetMapping(name = "获取问题列表", value = "/selectExamQuestionList")
    public Message<List<ExamQuestionListVo>> selectExamQuestionList(@RequestParam String questionBankCode, @RequestParam Long examId) {
        List<ExamQuestionListVo> examQuestionListVo = quizTbQuestionAnswerRecordService.selectExamQuestionListByBankCodeAndExamId(questionBankCode, examId);
        return Message.getInstance().setData(examQuestionListVo).success("查询成功");
    }

    @BizLog(name = "测验答题记录-根据ID查询", bizType = BizLogType.SELECT)
    @GetMapping(name = "根据ID查询", value = "/selectById")
    public Message<QuizTbQuestionAnswerRecord> selectById(@RequestParam Long id) {
        QuizTbQuestionAnswerRecord resultEntity = quizTbQuestionAnswerRecordService.selectById(id);
        return Message.getInstance().setData(resultEntity).success("查询成功");
    }

    @BizLog(name = "测验答题记录-新增", bizType = BizLogType.INSERT)
    @PostMapping(name = "新增", value = "/save")
    public Message<Long> saveEntity(@RequestBody @Valid QuizTbQuestionAnswerRecordAo entityAo) {
        quizTbQuestionAnswerRecordService.insertService(entityAo);
        return Message.getInstance().setData(entityAo.getId()).success();
    }

    @BizLog(name = "测验答题记录-批量新增", bizType = BizLogType.INSERT)
    @PostMapping(name = "批量新增", value = "/saveList")
    public Message<List<Long>> saveEntityList(@RequestBody @Valid List<QuizTbQuestionAnswerRecordAo> entityAos) {
        List<Long> ids = quizTbQuestionAnswerRecordService.insertList(entityAos);
        return Message.getInstance().setData(ids).success();
    }

    @BizLog(name = "测验答题记录-更新", bizType = BizLogType.UPDATE)
    @PostMapping(name = "更新", value = "/update")
    public Message<Boolean> updateEntity(@RequestBody @Valid QuizTbQuestionAnswerRecordAo entityAo) {
        quizTbQuestionAnswerRecordService.updateService(entityAo);
        return Message.getInstance().success();
    }

    @BizLog(name = "测验答题记录-批量更新", bizType = BizLogType.UPDATE)
    @PostMapping(name = "批量更新", value = "/updateList")
    public Message<Integer> updateEntityList(@RequestBody @Valid List<QuizTbQuestionAnswerRecordAo> entityAos) {
        Integer count = quizTbQuestionAnswerRecordService.updateListBySelective(entityAos);
        return Message.getInstance().setData(count).success();
    }

    @BizLog(name = "测验答题记录-逻辑删除", bizType = BizLogType.DELETE)
    @PostMapping(name = "逻辑删除", value = "/logicDelete")
    public Message<Boolean> logicDelete(@RequestBody List<Long> ids) {
        quizTbQuestionAnswerRecordService.logicDeleteByIds(ids);
        return Message.getInstance().success();
    }

    @BizLog(name = "测验答题记录-物理删除", bizType = BizLogType.DELETE)
    @PostMapping(name = "物理删除", value = "/delete")
    public Message<Boolean> delete(@RequestBody List<Long> ids) {
        quizTbQuestionAnswerRecordService.deleteServiceByIds(ids);
        return Message.getInstance().success();
    }


}
